package main

func countAlternatingSubarrays(nums []int) int64 {
	var count int64 = 0
	left := 0
	right := 0 // 左闭右开
	for left < len(nums) {
		right = left + 1
		for right < len(nums) && nums[right] != nums[right - 1] {
			right++
		}
		n := int64(right - left) 
		count += (n+1)*n/2
		left = right
	}
	return count
}

func main() {
	println(countAlternatingSubarrays([]int{0,1,1,1}))
}
